<template>
  <div class="aui-card-list">
  <uni-list-query-card :queryShow="queryShow" @query-click="getDataList()" @click="(e)=>{this.queryShow=e}" @searchReset="searchReset()">
      <el-col :span="6">
        <el-form-item label="模板编码">
          <el-input v-model="dataForm.tmpCode" placeholder="模板编码" clearable></el-input>
        </el-form-item>
      </el-col>
       <el-col :span="6">
        <el-form-item label="模板名称">
          <el-input v-model="dataForm.tmpName" placeholder="模板名称" clearable></el-input>
        </el-form-item>
      </el-col>
       <el-col :span="6">
        <el-form-item label="模板分类">
          <el-select v-model="dataForm.tmpType" placeholder="模板分类" clearable>
              <el-option v-for="template in $getDictList('GEN_TEMP_TYPE', true)" :key="template.val" :label="template.label" :value="template.val"></el-option>
            </el-select>
        </el-form-item>
      </el-col>
  </uni-list-query-card>
    <el-card shadow="never" class="aui-card-list-body">
      <vxe-toolbar :setting="{immediate:true}">
        <template v-slot:buttons>
          <el-button v-if="$hasPermission('gen:genTableType:save')" type="primary" @click="addOrUpdateHandle()">{{
            $t('add') }}
          </el-button>
          <el-button v-if="$hasPermission('gen:genTableType:delete')" type="danger" @click="deleteHandle()">{{
            $t('deleteBatch') }}
          </el-button>
        </template>
        <template v-slot:tools>
          <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
        </template>
      </vxe-toolbar>
      <div>
      <vxe-table ref="xTable" :loading="dataListLoading" class="vxe-table-element" auto-resize
        @select-change="dataListSelectionChangeHandleVex" @select-all="dataListSelectionAllChangeHandleVex"
        :data="dataList" max-height="auto">
        <vxe-table-column type="checkbox" align="center" width="60"></vxe-table-column>
        <vxe-table-column field="tmpCode" title="模板编码">
        </vxe-table-column>
        <vxe-table-column field="tmpName" title="模板名称">
        </vxe-table-column>
        <vxe-table-column field="tmpType" title="模板分类">
          <template slot-scope="scope">
            {{$getDictLabel('GEN_TEMP_TYPE', scope.row.tmpType)}}
          </template>
        </vxe-table-column>
        <vxe-table-column field="picture" title="模板预览图片">
        </vxe-table-column>
        <vxe-table-column field="sorts" align="center" width="80" title="排序">
        </vxe-table-column>
        <vxe-table-column field="updateDate" title="更新时间">
        </vxe-table-column>
        <vxe-table-column title="handle" fixed="right" align="left" width="240">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('gen:genTableTemplate:update')" type="text" size="small" icon="el-icon-edit"
              @click="addOrUpdateHandle(scope.row)">{{ $t('update') }}
            </el-button>
            <el-button v-if="$hasPermission('gen:genTableTemplate:update')" type="text" size="small" icon="el-icon-edit"
              @click="configTemp(scope.row)">关联代码文件
            </el-button>
            <el-button v-if="$hasPermission('gen:genTableTemplate:delete')" type="text" size="small"
              icon="el-icon-delete" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}
            </el-button>
          </template>
        </vxe-table-column>
      </vxe-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
        layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      </div>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </el-card>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './genTableType-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      searchShow: true,
      mixinViewModuleOptions: {
        getDataListURL: '/gen/genTableType/page',
        getDataListIsPage: true,
        deleteURL: '/gen/genTableType',
        deleteIsBatch: true,
        exportURL: '/gen/genTableType/export'
      },
      dataForm: {
        tmpCode: '',
        tmpName: '',
        tmpType: ''
      }
    }
  },
  components: {
    AddOrUpdate
  },
  methods: {
    // 新增 / 修改
    addOrUpdateHandle (row) {
      let id
      if (row) {
        id = row.id
      }
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.id = id
        this.$refs.addOrUpdate.init()
      })
    },
    // 设置代码文件
    configTemp (row) {
      let title, id
      if (row) {
        title = row.tmpName
        id = row.id
      }
      // 打开路由
      var router = {
        name: 'gen-genTableType-list',
        id: id,
        menuId: this.$route.meta.menuId,
        oldName: 'gen-genTableType',
        path: 'gen/genTableType-list',
        title: '代码文件清单--' + title
      }
      var params = {
        data: row
      }
      this.$options.methods.openNewTab(this.$router, router, params)
    }
  }
}
</script>
